import java.nio.channels.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;

public class Test {
	public static void main(String[] args){
		System.out.print("hellow world\n");
		Person p = new Person("小明");
		p.sayName();
		
		
		//实例变量测试
		Test1 t = new Test1();
		t.setTest2(123);
		System.out.println("\n"+t.getTest2());
		Test1.testSMethod();
		//测试增强for
		t.testFor();
		
		//格式化字符串
		String fs = String.format("格式化"+ "字符串");
		System.out.println(fs);
		
		//可变字符串
		StringBuilder testStr = new StringBuilder();
		testStr.append("可变字符串");
		System.out.println(testStr);
		
		//数组
		int [] a = new int[2];
		a[0] = 1;
		a[1] = 2;
//		
//		//时间计算
		System.out.println("\n当前时间:"+new Date().toString());
		
		//时间格式化
		Date dNow = new Date();
		SimpleDateFormat fomatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss 这个月第W周");
		String timeStr = String.format("\n指定时间格式"+ fomatter.format(dNow));
		System.out.println(timeStr);
		//指定时间转为时间戳
		SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");	
		try {
			Date newT = formatter1.parse("2017-3-12");
			System.out.println("\n时间戳"+newT.getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//正则表达式
		//只是用一次的情况
		String strcontent = "abcdefg";
		boolean ismatch = Pattern.matches(".*cde.*", strcontent);
		if (ismatch) {
			System.out.println("匹配");
		}
		//共享表达式的情况
		Pattern newp = Pattern.compile(".*cde.*");
		Matcher matcher = newp.matcher(strcontent);
		 if (matcher.matches()) {
			System.out.println("匹配");
		}
		//表达式组 通过()来分组
		 String line = "This order was placed for QT3000! OK?";
		 Pattern myPattern = Pattern.compile("(\\D*)(\\d+)");
		 Matcher newM = myPattern.matcher(line);
		 if (newM.find()) {
			 System.out.println("非数字组:"+newM.group(1));
			 System.out.println("数字组"+newM.group(2));
		}
		 //控制台输入流
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 
	}
}



class Test1 {
	int a = 10; 
	
	public int test1; //实例变量
	private int test2;  //私有变量
	
	//属性设置
	public int getTest2() {
		return test2;
	}
	public void setTest2(int test2) {
		this.test2 = test2;
	}
	
	static void testSMethod() {
		System.out.println("\n静态方法测试");
	}
	
	//增强for测试
	public void testFor() {
		int [] a = {1,2,3,4,5};
		for (int number : a) {
			System.out.println(number+" ");
		}
	}

}


